package cn.dubito.miaosha.controller;

import cn.dubito.miaosha.controller.vo.Result;
import cn.dubito.miaosha.param.LoginParam;
import cn.dubito.miaosha.service.SeckillUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author liliang
 * @description:
 * @date 2018/3/29.
 */
@Controller
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private SeckillUserService seckillUserService;

    @RequestMapping("/to_login")
    public String toLogin() {
        return "login";
    }

    @PostMapping("/login")
    @ResponseBody
    public Result<Boolean> login(HttpServletResponse response, @Valid LoginParam param) {

        logger.info("param:{}", param);

        return Result.success(seckillUserService.login(response,param));
    }
}
